import React, { Component } from 'react';
import { connect } from 'dva';
import router from 'umi/router';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

@connect(({ login, menu }) => ({
  systemList: login.systemList,
  menuData: menu.menuData,
}))
class Nsweb extends Component {

  componentDidMount() {
    if (this.props.systemList.length) {
      router.push(this.selectSysUrl());
    } else {
      this.props.dispatch({
        type: 'login/isLogin',
      })
    }
  }

  // 当前选择系统url
  selectSysUrl = () => {
    let url = '/user/login';
    this.props.systemList.map((item) => {
      if (item.isSelected) {
        // url = this.props.systemList[index].sysUrl.split("#")[1]
        url = (this.props.menuData.length && this.props.menuData[0].children) ? this.props.menuData[0].children[0].path : '/';
      }
    })
    return url
  }

  render() {
    return (
      <PageHeaderWrapper />
    );
  }
}

export default Nsweb;
